package com._常用API;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.ScheduledExecutorService;

/**
 * @author liyiruo
 * @Description
 * @Date 2023/2/15 下午3:37
 */
public class TimerDemo {

    public static String getDate(){

        SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String s = format.format(new Date());
        return s;
    }
    public static void startTimer() {
        TimerTask task=new TimerTask() {
            @Override
            public void run() {
                System.out.println(getDate());
            }
        };
        Timer timer=new Timer();
       // timer.schedule(task,1000);
        timer.schedule(task,1000,5000);

    }

    public static void main(String[] args) {
        startTimer();
    }
}
